package to52.android.adapters;

import to52.android.screens.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import fr.utbm.Patient;
import fr.utbm.PatientList;

public class PatientAdapter extends BaseAdapter {

    private static class ViewHolder {
        TextView name;
    }
	
	private Context mContext;
    private LayoutInflater mInflater;
    private PatientList patients;
    private ViewHolder holder;
	
    public int getCount() {
        return patients.size();
    }

    public Object getItem(int position) {
        return patients.get(position);
    }

    public long getItemId(int position) {
        return position;
    }
    
    
    public PatientAdapter(Context c, PatientList patientList) {
        mContext = c;
        mInflater = LayoutInflater.from(mContext);
        this.patients = patientList;
    }

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.patient_row, null);

            holder = new ViewHolder();
            holder.name = (TextView) convertView.findViewById(R.id.patient_row_name);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        Patient p = (Patient)getItem(position);

        holder.name.setText(p.getName());

        return convertView;
	}
	
}

